<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../css/common.css">
		<title>两票管理</title>
	</head>

	<body>
    <!-- <header class="mui-bar mui-bar-nav">
    	<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
    	<h1 class="mui-title">电子开票111</h1>
    </header> -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/jquery-1.7.2.min.js"></script>
		<script src="../../../js/vue.js"></script>
		<script src="./js/base64.js"></script>
		<script src="./js/xxtea.js"></script>
		<script src="./js/shoyu-xxtea.js"></script>
		<script src="../js/mkeyplus.base.js"></script>
		<script type="text/javascript">
			mui.init()
      var old_back = mui.back;
          mui.back = function() {
          	// old_back();
          }
      mui.plusReady(function(){
        cv = plus.webview.currentWebview();
        var userName = cv.username;
        var password = cv.password;
		var topage = cv.topage;
		var loginType = cv.loginType;
        console.log(userName)
        console.log(password)
        var subpage_style = {
            top: '0px',
            bottom: '0px',
            backButtonAutoControl: "none",
            // 'titleNView': {
            //     'backgroundColor': '#125CB7',
            //     'titleText': '电子开票',
            //     'titleColor': '#fff',
            //     'autoBackButton': true
            // }
        }
        
        var embed=plus.webview.create('./../tbl/index.html?userName=' + encodeURIComponent(userName) +'&password=' + encodeURIComponent(password)+'&page='+encodeURIComponent(topage)+'&loginType='+loginType ,'embed',subpage_style);
		console.log('?userName=' + encodeURIComponent(userName) +'&password=' + encodeURIComponent(password)+'&page='+encodeURIComponent(topage)+'&loginType='+loginType)
        var ws = plus.webview.currentWebview();
        ws.append(embed); 
        embed.addEventListener('loading',function(){       //当页面加载时
            plus.nativeUI.showWaiting('',{style:'black',modal:false,background:'rgba(0,0,0,0)'});
        },false);
        embed.addEventListener('loaded',function(){       //当页面加载完成时
            plus.nativeUI.closeWaiting();
        },false);
        plus.key.addEventListener('backbutton', function() {
          embed.canBack(function (evt) {
            console.log(JSON.stringify(evt))
            console.log(embed.id === plus.runtime.appid)
            // return
              /**  
               * 有可后退的历史记录，则后退。  
               * 否则，关闭当前窗口。  
               * 如果当前窗口是入口页，那么执行退出的逻辑。  
               */  
              if (embed.id === plus.runtime.appid) {  
                  // if (!firstBack) {  
                  //     firstBack = now();  
                  //     plus.nativeUI.toast('再按一次退出应用');  
                    
                  //     setTimeout(function () {  
                  //         firstBack = 0;  
                  //     }, 2000);  
                  // } else if (now() - firstBack < 2000) {  
                  //     plus.runtime.quit();  
                  // }  
              } else {
                  if (evt.canBack) {
                      embed.back();  
                      console.log(11)
                  } else {
                    console.log(222)
                    old_back()
                  }  
              }  
          });  
        }); 
        
      })
      
      var handleBack = function () {
              var currentWebview = plus.webview.currentWebview();  
              var topWebview = plus.webview.getTopWebview();  
              var now = Date.now || function () {  
                  return new Date().getTime();  
              };  
      
              currentWebview.canBack(function (evt) {  
                  /**  
                   * 有可后退的历史记录，则后退。  
                   * 否则，关闭当前窗口。  
                   * 如果当前窗口是入口页，那么执行退出的逻辑。  
                   */  
                  if (currentWebview.id === plus.runtime.appid) {  
                      if (!firstBack) {  
                          firstBack = now();  
                          plus.nativeUI.toast('再按一次退出应用');  
      
                          setTimeout(function () {  
                              firstBack = 0;  
                          }, 2000);  
                      } else if (now() - firstBack < 2000) {  
                          plus.runtime.quit();  
                      }  
                  } else {  
                      if (evt.canBack) {  
                          history.back();  
                      } else {  
                          currentWebview.close('auto');  
                      }  
                  }  
              });  
          };
		</script>
	</body>

</html>
